package com.lyc.oj.judge.codesandbox;

import com.lyc.oj.judge.codesandbox.impl.ExampleCodeSandbox;
import com.lyc.oj.judge.codesandbox.impl.RemoteCodeSandbox;
import com.lyc.oj.judge.codesandbox.impl.ThirdPartyCodeSandbox;
import com.lyc.oj.model.enums.CodeSandboxEnum;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Scanner;

/**
 * 静态工厂模式
 * 代码沙箱工厂（根据字符串参数创建指定的代码沙箱实例）
 */
@ConfigurationProperties(prefix = "codesandbox")
@Configuration
@Data
public class CodeSandboxFactory {

    private CodeSandboxEnum type = CodeSandboxEnum.EXAMPLE;

    public CodeSandbox newInstance() {
        return newInstance(type);
    }

    public static CodeSandbox newInstance(CodeSandboxEnum customerType) {
        if (customerType == null) {
            customerType = CodeSandboxEnum.EXAMPLE;
        }
        switch (customerType) {
            case REMOTE:
                return new RemoteCodeSandbox();
            case THIRD_PARTY:
                return new ThirdPartyCodeSandbox();
            case EXAMPLE:
            default:
                return new ExampleCodeSandbox();
        }
    }
}
